/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'http',
        hostname: '139.159.190.115',
        port: '9000',
        pathname: '/**',
      },
      // Allow images served directly from MinIO IP
      {
        protocol: 'http',
        hostname: '175.178.120.172',
        port: '9000',
        pathname: '/kason-world/**',
      },
      // Allow images served via public domain, if used
      {
        protocol: 'https',
        hostname: 'www.kason.top',
        port: '',
        pathname: '/kason-world/**',
      },
    ],
  },

  // 优化构建性能和内存使用
  experimental: {
    // 减少内存使用
    workerThreads: false,
    cpus: 1,
  },

  // 排除不需要的文件
  webpack: (config, { isServer }) => {
    // 排除 scripts 目录
    config.watchOptions = {
      ...config.watchOptions,
      ignored: ['**/scripts/**', '**/node_modules/**'],
    };

    // 优化内存使用
    config.optimization = {
      ...config.optimization,
      splitChunks: {
        chunks: 'all',
        cacheGroups: {
          default: {
            minChunks: 1,
            priority: -20,
            reuseExistingChunk: true,
          },
          vendor: {
            test: /[\\/]node_modules[\\/]/,
            name: 'vendors',
            priority: -10,
            chunks: 'all',
          },
        },
      },
    };

    // 限制并行处理数量以减少内存使用
    config.parallelism = 1;

    return config;
  },
};

module.exports = nextConfig;